﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Mimoza.Common;

namespace Mimoza.ObjectLayer
{
    public class Policy : INotifyPropertyChanged
    {
        private OL ol;
        private PolicyRecord record = new PolicyRecord();
        public Policy(OL ol)
        {
            this.ol = ol;
        }
        public Policy(OL ol, PolicyRecord record)
        {
            this.ol = ol;
            this.record = record;
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        public PolicyRecord Record
        {
            get
            {
                return record;
            }
        }
        public Guid ID
        {
            get { return record.ID; }
        }
        public Container Parent
        {
            get
            {
                if (record.ParentID != null)
                {
                    return ol.ContainerRepository.GetContainerByID(record.ParentID);
                }
                else
                {
                    return null;
                }
            }
            set
            {
                if (value.Record.ID != this.record.ParentID)
                {
                    record.ParentID = value.ID;
                    NotifyPropertyChanged("Parent");
                }
            }
        }
        public string Name
        {
            get { return record.Name; }
            set {
                if (value != this.record.Name)
                {
                    record.Name = value;
                    NotifyPropertyChanged("Name");
                }
            }
        }
        public string Description
        {
            get { return record.Description; }
            set
            {
                if (value != this.record.Description)
                {
                    record.Description = value;
                    NotifyPropertyChanged("Description");
                }
            }
        }
        public string PluginID
        {
            get { return record.PluginID; }
            set
            {
                if (value != this.record.PluginID)
                {
                    record.PluginID = value;
                    NotifyPropertyChanged("PluginID");
                }
            }
        }
        public bool IsEnabled
        {
            get { return record.IsEnabled; }
            set
            {
                if (value != this.record.IsEnabled)
                {
                    record.IsEnabled = value;
                    NotifyPropertyChanged("IsEnabled");
                }
            }
        }
        public bool IsHardware
        {
            get { return record.IsHardware; }
            set
            {
                if (value != this.record.IsHardware)
                {
                    record.IsHardware = value;
                    NotifyPropertyChanged("IsHardware");
                }
            }
        }
        public bool IsMultiple
        {
            get { return record.IsMultiple; }
            set
            {
                if (value != this.record.IsMultiple)
                {
                    record.IsMultiple = value;
                    NotifyPropertyChanged("IsMultiple");
                }
            }
        }
        public bool Override
        {
            get { return record.Override; }
            set
            {
                if (value != this.record.Override)
                {
                    record.Override = value;
                    NotifyPropertyChanged("Override");
                }
            }
        }
        public Guid UpdatesID
        {
            get { return record.UpdatesID; }
            set
            {
                if (value != this.record.UpdatesID)
                {
                    record.UpdatesID = value;
                    NotifyPropertyChanged("UpdatesID");
                }
            }
        }
        public Guid DataModificationID
        {
            get { return record.DataModificationID; }
            set
            {
                if (value != this.record.DataModificationID)
                {
                    record.DataModificationID = value;
                    NotifyPropertyChanged("DataModificationID");
                }
            }
        }
        public string Data
        {
            get { return record.Data; }
            set
            {
                if (value != this.record.Data)
                {
                    record.Data = value;
                    NotifyPropertyChanged("Data");
                }
            }
        }
        public DateTime UpdateDate
        {
            get { return record.UpdateDate; }
        }
    }
}
